package com.tr.state;

import java.lang.management.ThreadMXBean;

/**
 * @author TRasdzz
 * @since  2021/3/10 20:11
 * @version  version-1.0
 */

//测试线程的优先级
public class TestPriority {
    public static void main(String[] args) {
        //主线程的，默认优先级
        System.out.println(Thread.currentThread().getName() + "--->" + Thread.currentThread().getPriority());

        MyPriority myPriority = new MyPriority();

        Thread t1 = new Thread(myPriority,"t1");
        Thread t2 = new Thread(myPriority,"t2");
        Thread t3 = new Thread(myPriority,"t3");
        Thread t4 = new Thread(myPriority,"t4");
        Thread t5 = new Thread(myPriority,"t5");
        Thread t6 = new Thread(myPriority,"t6");

        //先设置优先级再启动
        t1.setPriority(Thread.MIN_PRIORITY); //MIN_PRIORITY = 1
        t1.start();

        t2.setPriority(Thread.MAX_PRIORITY); //MAX_PRIORITY = 10
        t2.start();

        t3.setPriority(Thread.NORM_PRIORITY);//NORM_PRIORITY = 5
        t3.start();

        t4.setPriority(8);
        t4.start();

        t5.setPriority(7);
        t5.start();

        t6.setPriority(9);
        t6.start();


    }
}

class MyPriority implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "--->" + Thread.currentThread().getPriority());
    }
}
//main--->5
//t1--->1
//t2--->10
//t3--->5
//t4--->8
//t5--->7
//t6--->9